Some(path) => path,
None => exe,
};
- let process = compile.process(exe).args(args);
+ let process = compile.process(exe, &root).args(args).cwd(os::getcwd());
try!(options.shell.status("Running", process.to_string()));
Ok(process.exec().err())
use std::collections::HashMap;
use std::dynamic_lib::DynamicLibrary;
use std::os;
+use semver::Version;
-use core::PackageId;
+use core::{PackageId, Package};
use util;
/// A structure returning the result of a compilation.
/// Prepares a new process with an appropriate environment to run against
/// the artifacts produced by the build process.
- pub fn process<T: ToCStr>(&self, cmd: T) -> util::ProcessBuilder {
+ ///
+ /// The package argument is also used to configure environment variables as
+ /// well as the working directory of the child process.
+ pub fn process<T: ToCStr>(&self, cmd: T, pkg: &Package)
+ -> util::ProcessBuilder {
let mut search_path = DynamicLibrary::search_path();
for dir in self.native_dirs.values() {
search_path.push(dir.clone());
for (k, v) in self.extra_env.iter() {
cmd = cmd.env(k.as_slice(), v.as_ref().map(|s| s.as_slice()));
}
- return cmd;
+
+ cmd.env("CARGO_MANIFEST_DIR", Some(pkg.get_manifest_path().dir_path()))
+ .env("CARGO_PKG_VERSION_MAJOR",
+ Some(pkg.get_version().major.to_string()))
+ .env("CARGO_PKG_VERSION_MINOR",
+ Some(pkg.get_version().minor.to_string()))
+ .env("CARGO_PKG_VERSION_PATCH",
+ Some(pkg.get_version().patch.to_string()))
+ .env("CARGO_PKG_VERSION_PRE",
+ pre_version_component(pkg.get_version()))
+ .cwd(pkg.get_root())
+ }
+}
+
+fn pre_version_component(v: &Version) -> Option<String> {
+ if v.pre.is_empty() {
+ return None;
}
+
+ let mut ret = String::new();
+
+ for (i, x) in v.pre.iter().enumerate() {
+ if i != 0 { ret.push_char('.') };
+ ret.push_str(x.to_string().as_slice());
+ }
+
+ Some(ret)
}
use std::collections::{HashMap, HashSet};
use std::str;
-use semver::Version;
use core::{SourceMap, Package, PackageId, PackageSet, Resolve, Target};
use util::{mod, CargoResult, ChainError, internal, Config, profile, Require};
self.compilation.root_output = self.layout(KindTarget).proxy().dest().clone();
self.compilation.deps_output = self.layout(KindTarget).proxy().deps().clone();
- let env = &mut self.compilation.extra_env;
- env.insert("CARGO_PKG_VERSION_MAJOR".to_string(),
- Some(pkg.get_version().major.to_string()));
- env.insert("CARGO_PKG_VERSION_MINOR".to_string(),
- Some(pkg.get_version().minor.to_string()));
- env.insert("CARGO_PKG_VERSION_PATCH".to_string(),
- Some(pkg.get_version().patch.to_string()));
- env.insert("CARGO_PKG_VERSION_PRE".to_string(),
- pre_version_component(pkg.get_version()));
-
return Ok(());
-
- fn pre_version_component(v: &Version) -> Option<String> {
- if v.pre.is_empty() {
- return None;
- }
-
- let mut ret = String::new();
-
- for (i, x) in v.pre.iter().enumerate() {
- if i != 0 { ret.push_char('.') };
- ret.push_str(x.to_string().as_slice());
- }
-
- Some(ret)
- }
}
fn build_requirements(&mut self, pkg: &'a Package, target: &'a Target,
// We want to use the same environment and such as normal processes, but we
// want to override the dylib search path with the one we just calculated.
- cx.compilation.process(cmd).cwd(pkg.get_root())
- .env(DynamicLibrary::envvar(),
- Some(search_path.as_slice()))
+ cx.compilation.process(cmd, pkg)
+ .env(DynamicLibrary::envvar(), Some(search_path.as_slice()))
}
Some(path) => path,
None => exe.clone(),
};
- let cmd = compile.process(exe).args(args);
+ let cmd = compile.process(exe, &package).args(args);
try!(options.shell.concise(|shell| {
shell.status("Running", to_display.display().to_string())
}));
for (lib, name) in libs {
try!(options.shell.status("Doc-tests", name));
- let mut p = compile.process("rustdoc")
+ let mut p = compile.process("rustdoc", &package)
.arg("--test").arg(lib)
.arg("--crate-name").arg(name)
.arg("-L").arg(&compile.root_output)
static VERSION_MINOR: &'static str = env!("CARGO_PKG_VERSION_MINOR");
static VERSION_PATCH: &'static str = env!("CARGO_PKG_VERSION_PATCH");
static VERSION_PRE: &'static str = env!("CARGO_PKG_VERSION_PRE");
+ static CARGO_MANIFEST_DIR: &'static str = env!("CARGO_MANIFEST_DIR");
fn main() {
- let s = format!("{}-{}-{} @ {}", VERSION_MAJOR, VERSION_MINOR,
- VERSION_PATCH, VERSION_PRE);
+ let s = format!("{}-{}-{} @ {} in {}", VERSION_MAJOR,
+ VERSION_MINOR, VERSION_PATCH, VERSION_PRE,
+ CARGO_MANIFEST_DIR);
assert_eq!(s, foo::version());
println!("{}", s);
}
"#)
.file("src/lib.rs", r#"
pub fn version() -> String {
- format!("{}-{}-{} @ {}",
+ format!("{}-{}-{} @ {} in {}",
env!("CARGO_PKG_VERSION_MAJOR"),
env!("CARGO_PKG_VERSION_MINOR"),
env!("CARGO_PKG_VERSION_PATCH"),
- env!("CARGO_PKG_VERSION_PRE"))
+ env!("CARGO_PKG_VERSION_PRE"),
+ env!("CARGO_MANIFEST_DIR"))
}
"#);
assert_that(
process(p.bin("foo")),
- execs().with_stdout("0-5-1 @ alpha.1\n"));
+ execs().with_stdout(format!("0-5-1 @ alpha.1 in {}\n",
+ p.root().display()).as_slice()));
assert_that(p.process(cargo_dir().join("cargo-test")), execs().with_status(0));
})